package tech.aistar.day11;

import java.util.concurrent.TimeUnit;

/**
 * 本类用来演示: 线程的礼让 - 暂停当前的线程
 *             只能礼让同优先级的线程 - "不一定让得出去"
 *
 * @author: success
 * @date: 2022/8/2 4:35 下午
 */
public class YieldDemo extends Thread{
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName()+":"+i);
            if(i==5){
                Thread.yield();
            }
        }
    }

    public static void main(String[] args) {
        Thread t1 = new YieldDemo();
        Thread t2 = new YieldDemo();

        t1.start();
        t2.start();
    }
}

